﻿using HalconDotNet;
using LD.Host;
using LD.Tool;
using LD.Vision;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media;
using 右下角弹窗.DiagShow;

namespace LD.Tool
{
    public partial class ToolBarcode2DFrm : FrmVisionToolBase
    {
        public ToolBarcode2DFrm()
        {
            InitializeComponent();
            this.Shown += ToolTemplateMatchHightFrm_Shown;
            this.btn_ok.Click += Btn_ok_Click;
            Init();
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            var param = new ToolBarcode2DParam()
            {
                CameraName = this.CameraName,
                ImageSource = this.txt_imagePath.Text,
            };
            this.TB_Tool.Param = Newtonsoft.Json.JsonConvert.SerializeObject(param);
        }

        private void ToolTemplateMatchHightFrm_Shown(object sender, EventArgs e)
        {
            InitParam();
        }

        private void Init()
        {
            InitUI();
        }
        private void InitUI()
        {

        }
        private void InitParam()
        {
            var param = Newtonsoft.Json.JsonConvert.DeserializeObject<ToolBarcode2DParam>(TB_Tool.Param);
            if (param != null)
            {
                this.CameraName = param.CameraName;
                this.txt_imagePath.Text = param.ImageSource;
            }
        }
        private void btn_dir_Click(object sender, EventArgs e)
        {
            //弹窗
            using (var ofd = new OpenFileDialog())
            {
                ofd.Title = "打开数据";
                //ofd.Filter = "(*.bmp)|*.bmp|(*.jpg) | *.jpg";
                ofd.Filter = "(*.ldc)|*.ldc;";
                ofd.RestoreDirectory = true;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string fileName = ofd.FileName;
                    TB_Tool.Param = fileName;
                }
            }
        }

        private void btn_bind_Click(object sender, EventArgs e)
        {
            FrmOutputBind bindFrm = new FrmOutputBind(TB_Tool.FlowName, typeof(HImage));
            if (bindFrm.ShowDialog() == DialogResult.OK)
            {
                var bind = bindFrm.BindOutput;
                this.txt_imagePath.Text = bind;
            }
        }
    }
}
